﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfStudy.Command
{
    /// <summary>
    /// SecondForm.xaml 的交互逻辑
    /// </summary>
    public partial class SecondForm : Window
    {
        public SecondForm()
        {
            InitializeComponent();
        }

        private void New_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(TextBoxName.Text)){
                e.CanExecute = false;
            }
            else
            {
                e.CanExecute = true;
            }
            e.Handled = true;
        }

        private void New_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            string name = TextBoxName.Text;
            if ("teacher".Equals(e.Parameter.ToString().ToLower()))
            {
                listBoxSay.Items.Add($"New Teacher {name}：学而不厌，诲人不倦。");
            }
            if ("student".Equals(e.Parameter.ToString().ToLower()))
            {
                listBoxSay.Items.Add($"New Student {name}：好好学习，天天向上。");
            }

            e.Handled = true;
        }
    }
}
